package com.ruoyi.system.pay.mapper;

import com.ruoyi.system.pay.domain.po.PayTransaction;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 支付流水表 Mapper
 */
@Mapper
public interface PayTransactionMapper {

    /**
     * 通过订单 ID 查询支付流水
     */
    @Select("SELECT * FROM pay_transaction WHERE order_id = #{orderId}")
    List<PayTransaction> findByOrderId(@Param("orderId") Long orderId);

    /**
     * 通过支付交易号查询流水
     */
    @Select("SELECT * FROM pay_transaction WHERE transaction_id = #{transactionId}")
    PayTransaction findByTransactionId(@Param("transactionId") String transactionId);

    /**
     * 新增支付流水记录
     */
    @Insert("INSERT INTO pay_transaction (order_id, transaction_id, amount, pay_method, status, transaction_time, created_at) " +
            "VALUES (#{orderId}, #{transactionId}, #{amount}, #{payMethod}, #{status}, NOW(), NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertTransaction(PayTransaction transaction);

    /**
     * 更新支付流水状态
     */
    @Update("UPDATE pay_transaction SET status = #{status} WHERE transaction_id = #{transactionId}")
    int updateTransactionStatus(@Param("transactionId") String transactionId, @Param("status") String status);
}
